﻿import com.crystalcentral.model.*;
import com.crystalcentral.view.*;
import com.crystalcentral.*;

import mx.utils.Delegate;

import com.darronschall.DynamicRegistration;

class com.crystalcentral.view.MImage extends com.crystalcentral.view.MItem
{
	var diyImageItem:DiyImageItem;
	var image:MovieClip;
	
	var BORDER_WIDTH   = 1;
	var PADDING_TOP    = 0;
	var PADDING_BOTTOM = 0;
	var PADDING_LEFT   = 0;
	var PADDING_RIGHT  = 0;
	
	// Constants:
	public static var CLASS_REF = com.crystalcentral.view.MImage;

	public function MImage(diyItem:DiyImageItem, mCanvas:MCanvas)
	{
		// constructor code
		super(diyItem,mCanvas);
		this.diyImageItem = diyItem;
		this.image = this.mcContent;
		
		_root.diyTool.startLoading("Loading Image into Canvas...");
		
		var mcl:MovieClipLoader = new MovieClipLoader();
		var listener = new Object();
		listener.onLoadInit = Delegate.create(this, onLoadImage);
		listener.onLoadError = function() {
			trace("MImage: onLoadError");
			_root.diyTool.stopLoading();
		}
		mcl.addListener(listener);
		mcl.loadClip(DiyTool.HOST + diyItem.src, this.image);
	}
	
	function onLoadImage () {
		trace("MImage:onLoadImage()");
		//initActions();
		registerClickEvent();
		this.mcItem.setRegistration(this.mcContent._width/2, this.mcContent._height/2);
		this.diyItem.width = this.mcContent._width;
		this.diyItem.height = this.mcContent._height;
		
		_root.diyTool.stopLoading();
	}
	
	function setOnFocus() {
		super.setOnFocus();
	}
	function setLostFocus() {
		super.setLostFocus();
	}

	function drawBorder() {
		super.drawBorder();
	}
	
	function onItemPress()
	{
		super.onItemPress();
	}

	function onItemRelease()
	{
		super.onItemRelease();
	}

	function onItemReleaseOutside()
	{
		super.onItemReleaseOutside();
	}
	
	function showEditTools() {
		super.showEditTools();
		this.mcResizeText._visible = false;
	}
	
	function initEditToolActions() {
		super.initEditToolActions();
	}
}